package stores

import (
	"lesson01/instructions/base"
	"lesson01/rtda"
)

type DStore struct {
	base.Index8Instruction
}

func (e *DStore) Execute(frame *rtda.Frame) {
	_dstore(frame, uint(e.Index))
}

type DStore_0 struct {
	base.NoOperandsInstruction
}

func (e *DStore_0) Execute(frame *rtda.Frame) {
	_dstore(frame, 0)
}

type DStore_1 struct {
	base.NoOperandsInstruction
}

func (e *DStore_1) Execute(frame *rtda.Frame) {
	_dstore(frame, 1)
}

type DStore_2 struct {
	base.NoOperandsInstruction
}

func (e *DStore_2) Execute(frame *rtda.Frame) {
	_dstore(frame, 2)
}

type DStore_3 struct {
	base.NoOperandsInstruction
}

func (e *DStore_3) Execute(frame *rtda.Frame) {
	_dstore(frame, 3)
}

func _dstore(frame *rtda.Frame, index uint) {
	val := frame.OperandStack().PopDouble()
	frame.LocalVars().SetDouble(index, val)
}
